package com.huisang.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huisang.pojo.User;
import com.huisang.util.Constants;

public class UserPowerFilter implements Filter {
    
    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest) req;
        HttpServletResponse response=(HttpServletResponse) resp;
        User user=(User)request.getSession().getAttribute(Constants.USER_SESSION);
        String method=request.getParameter("method");
        if(method.equals("pwdmodify")&&method!=null){
            chain.doFilter(req, resp);
        }else if(method.equals("savepwd")&&method!=null){
            chain.doFilter(req, resp);
        }else if(user.getUserRole()!=1){
            response.sendRedirect(request.getContextPath()+"/jurisdictionError.jsp");
        }else{
            chain.doFilter(req, resp);
        }
    }
}
